import 'dart:async';

import 'package:flutter/services.dart';

class TrackingIO {
  static const MethodChannel _channel =
      const MethodChannel('flutter_trackingio');

  static Future<void> setDebugMode({required bool debug}) async {
    await _channel.invokeMethod('setDebugMode', {
      'debug': debug,
    });
  }

  static Future<void> initWithKeyAndChannelId(
    String appKey, {
    String channelId = '_default_',
  }) async {
    await _channel.invokeMethod('initWithKeyAndChannelId', {
      'appKey': appKey,
      'channelId': channelId,
    });
  }

  static Future<void> setRegisterWithAccountID(String accountId) async {
    await _channel.invokeMethod('setRegisterWithAccountID', {
      'accountId': accountId,
    });
  }

  static Future<void> setLoginSuccessBusiness(String accountId) async {
    await _channel.invokeMethod('setLoginSuccessBusiness', {
      'accountId': accountId,
    });
  }

  static Future<void> setPayment({
    required String transactionId,
    required String paymentType,
    required String currencyType,
    required double currencyAmount,
  }) async {
    await _channel.invokeMethod('setPayment', {
      'transactionId': transactionId,
      'paymentType': paymentType,
      'currencyType': currencyType,
      'currencyAmount': currencyAmount,
    });
  }

  static Future<void> setOrder({
    required String transactionId,
    required String currencyType,
    required double currencyAmount,
  }) async {
    await _channel.invokeMethod('setOrder', {
      'transactionId': transactionId,
      'currencyType': currencyType,
      'currencyAmount': currencyAmount,
    });
  }

  static Future<void> setEvent(String eventName) async {
    await _channel.invokeMethod('setEvent', {
      'eventName': eventName,
    });
  }

  static Future<void> setAdShow({
    required String adPlatform,
    required String adId,
    required String fill,
  }) async {
    await _channel.invokeMethod('setAdShow', {
      'adPlatform': adPlatform,
      'adId': adId,
      'fill': fill,
    });
  }

  static Future<void> setAdClick({
    required String adPlatform,
    required String adId,
  }) async {
    await _channel.invokeMethod('setAdClick', {
      'adPlatform': adPlatform,
      'adId': adId,
    });
  }

  static Future<void> setAppDuration(int duration) async {
    await _channel.invokeMethod('setAppDuration', {
      'duration': duration,
    });
  }

  static Future<void> setPageDuration(String activityName, int duration) async {
    await _channel.invokeMethod('setPageDuration', {
      'activityName': activityName,
      'duration': duration,
    });
  }

  static Future<void> exitSdk() async {
    await _channel.invokeMethod('exitSdk');
  }
}
